package com.ruoyi.web.controller.system;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSendTask;
import com.ruoyi.system.service.ISysSendTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 群发记录总单Controller
 * 
 * @author ruoyi
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/system/sendtask")
public class SysSendTaskController extends BaseController
{
    @Autowired
    private ISysSendTaskService sysSendTaskService;

    /**
     * 查询群发记录总单列表
     */
    @PreAuthorize("@ss.hasPermi('system:sendtask:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSendTask sysSendTask)
    {
        startPage();
        List<SysSendTask> list = sysSendTaskService.selectSysSendTaskList(sysSendTask);
        return getDataTable(list);
    }

    /**
     * 导出群发记录总单列表
     */
    @PreAuthorize("@ss.hasPermi('system:sendtask:export')")
    @Log(title = "群发记录总单", businessType = BusinessType.EXPORT)
    @PostMapping(value = {"/export/{ids}","/export"})
    public void export(HttpServletResponse response, SysSendTask sysSendTask,@PathVariable(required = false) Long[] ids) throws ServletException, IOException {
        Map<String,Map<String,List<Map<String,String>>>> list = sysSendTaskService.inintReturnTxt(ids );
        ExcelUtil<SysSendTask> util = new ExcelUtil<SysSendTask>(SysSendTask.class);
        util.exportTxt(response, list );
    }

    /**
     * 获取群发记录总单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sendtask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysSendTaskService.selectSysSendTaskById(id));
    }

    /**
     * 新增群发记录总单
     */
    @PreAuthorize("@ss.hasPermi('system:sendtask:add')")
    @Log(title = "群发记录总单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSendTask sysSendTask)
    {
        return toAjax(sysSendTaskService.insertSysSendTask(sysSendTask));
    }

    /**
     * 修改群发记录总单
     */
    @PreAuthorize("@ss.hasPermi('system:sendtask:edit')")
    @Log(title = "群发记录总单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSendTask sysSendTask)
    {
        return toAjax(sysSendTaskService.updateSysSendTask(sysSendTask));
    }

    /**
     * 删除群发记录总单
     */
    @PreAuthorize("@ss.hasPermi('system:sendtask:remove')")
    @Log(title = "群发记录总单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysSendTaskService.deleteSysSendTaskByIds(ids));
    }
}
